//页面初始化
$(function(){
	// 初始化tab
	initTab();
	//关闭新增窗口
	$("#closeBtn").click(function() {
		backendCommon.closeWin("noPassWin");
	});
});

//打开审核拒绝窗口
function openNoPassWin(id) {
	//初始化窗口
	$("#appId").val(id);
	backendCommon.formReset("noPassForm");
	backendCommon.openeWin('noPassWin');
	$("#saveBtn").unbind('click').click(function() {
		verifyNo();
	});
}

// 审核通过
function verifyPass(id){
	var param = {
			'id':id,
			'rn':Math.random()
	};
	$.post(mainDomain+'/info/infoPublishVerify/infoPublishVerifyPass.action', param, function(result){
		if (result.success && result.state == 1) {
			$.messager.alert('提示','操作成功', 'info');
			backendCommon.closeWin('noPassWin');
			var options = $('#tt0').datagrid('getPager').data("pagination").options;  
            var curr = options.pageNumber;  
            $('#tt0').datagrid('getPager').pagination({
                 'pageNumber' : curr
            });
            $('#tt0').datagrid('reload');
		} else {
			$.messager.alert('提示', result.message, 'error');
		}
	});
}

// 审核拒绝
function verifyNo(){
	var id = $('#appId').val();
	var remark = $('#remark').val().trim();
	if(remark == ''){
		$.messager.alert('提示', '回复意见不能为空', 'error');
		return false;
	}
	if(remark.length > 250){
		$.messager.alert('提示', '回复意见不能操作250个长度', 'error');
		return false;
	}
	var param = {
			'id':id,
			'remark':remark,
			'rn':Math.random()
	};
	$.post(mainDomain+'/info/infoPublishVerify/infoPublishVerifyNoPass.action', param, function(result){
		if (result.success && result.state == 1) {
			$.messager.alert('提示','操作成功', 'info');
			backendCommon.closeWin('noPassWin');
			var options = $('#tt0').datagrid('getPager').data("pagination").options;  
            var curr = options.pageNumber;  
            $('#tt0').datagrid('getPager').pagination({
                 'pageNumber' : curr
            });
            $('#tt0').datagrid('reload');
		} else {
			$.messager.alert('提示', result.message, 'error');
		}
	});
}

// 进入发布申请 详情页 
function intoPublishDetailPage(id){
	//backendCommon.openInTabs(mainDomain+'/info/infoPublishDetailPage/'+id+'.action',"发布申请详情");  
	window.open(mainDomain+'/info/infoPublishDetailPage/'+id+'.action');
}

// 进入发布申请   编辑页/info/publish/{id}
function intoEditPublishDetailPage(id){
	backendCommon.openInTabs(mainDomain+'/info/publish/'+id+'.action', "发布申请编辑");  
	/*window.open(,,
	 "height=620, width=950, toolbar =no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");*/
}

// 初始化tab
var initTab = function(){
	$('#tab1').tabs('add',
    	{    
	    title:'待审核',    
	    content:"<table id='tt0' style='padding:20px;margin-top:10px;'></table>",    
	    closable:false,
	    tools:[{
			iconCls:'icon-reload',
			handler:function(){
				initTable(0);
			}
		}]
	});
    
    $('#tab1').tabs('add',
    	{    
	    title:'审核通过',    
	    content:"<table id='tt1' style='padding:10px;'></table>",    
	    closable:false,
	    tools:[{
			iconCls:'icon-reload',
			handler:function(){
				initTable(1);
			}
		}]
	});
    
    $('#tab1').tabs('add',
    	{    
	    title:'审核未通过',    
	    content:"<table id='tt2' style='padding:10px;'></table>",    
	    closable:false,
	    tools:[{
			iconCls:'icon-reload',
			handler:function(){
				initTable(2);
			}
		}]
    });
    $('#tab1').tabs({
    	cache:false,
        border:false,
        fit:true,
        tabHeight:36,
        onSelect:function(title){
    		if(title == '待审核'){
    			initTable(0);
    		}
    		if(title == '审核通过'){
    			initTable(1);
    		}
    		
    		if(title == '审核未通过'){
    			initTable(2);
    		}
        }
    });
};

//初始化列表页面
function initTable(i) {
	if(i == 0){
		$('#tt0').datagrid({
			title:'待审核列表信息',
			width : backendCommon.getWidth(0.94),
			height : 'auto',
			loadMsg:"数据装载中,请稍等....",
			url:mainDomain+'/info/infoPublishVerify/findInfoPublishPgByDto.action?publishStatus=0',
			nowrap: false,
			rownumbers:true,
			striped : true,
			fitColumns: true,
			pagination:true,
	        singleSelect:true,
	        pageSize:10,
		    pageNumber:1,          
		    pageList:[10,15,20],
			columns : [[
						{field : 'createBy',title : '提交人',width :$(this).width() * 0.10,align : 'center'},
						{field : 'content',title : '内容',width : $(this).width() * 0.35,align : 'center',
							formatter:function(value,rec){
								var count = '<a class="publish" onclick="intoPublishDetailPage('+rec.id+');"  title="进入详情页" href="javascript:void(0)">';
								if(rec.detailVoList != null && rec.detailVoList.length>0){
									$.each(rec.detailVoList,function(index,detail){
										count +=detail.infoTitle+'<br/>';
									});
								}
								count +='</a>';
								return count;
							 }
						},
						{field : 'createTime',title : '提交时间',width :$(this).width() * 0.20,align : 'center',
							formatter : function(value, rec, index) {
								var str = "";
								if(value != '') {
									str = backendCommon.dateTimeToLocalStringWithSeconds(rec.createTime);
								}
								return str;
							}
						},
						{field : 'appointmentTime',title : '发布时间',width :$(this).width() * 0.20,align : 'center',
							formatter : function(value, rec, index) {
								var str = '立即';
								if(value != '' && value !=null) {
									str = backendCommon.dateTimeToLocalStringWithSeconds(value);
								}
								return str;
							}
						},
						{field : 'uid',title : '操作',width : $(this).width() * 0.15,align : 'center',
							 formatter:function(value,rec){
								 var b = '<a class="publish" onclick="verifyPass('+rec.id+');" href="javascript:void(0)"  style="width:80px" >审核通过</a>';
								 b = b +'&nbsp;&nbsp;';
								 b = b+'<a class="publish" onclick="openNoPassWin('+rec.id+');" href="javascript:void(0)"  style="width:80px" >审核拒绝</a>';
								 return b;
							   }
						}
					]]
		});
	}
	if(i == 1){
		$('#tt1').datagrid({
			title:'审核通过列表信息',
			width : backendCommon.getWidth(0.94),
			height : 'auto',
			loadMsg:"数据装载中,请稍等....",
			url:mainDomain+'/info/infoPublishVerify/findInfoPublishPgByDto.action?publishStatus=3',
			nowrap: false,
			rownumbers:true,
			striped : true,
			fitColumns: true,
			pagination:true,
	        singleSelect:true,
	        pageSize:10,
		    pageNumber:1,          
		    pageList:[10,15,20],
			columns : [[
						{field : 'createBy',title : '提交人',width : $(this).width() * 0.10,align : 'center'},
						{field : 'content',title : '内容',width : $(this).width() * 0.35,align : 'center',
							formatter:function(value,rec){
								var count = '<a onclick="intoPublishDetailPage('+rec.id+');" class="publish" title="进入详情页" href="javascript:void(0)">';
								if(rec.detailVoList != null && rec.detailVoList.length>0){
									$.each(rec.detailVoList,function(index,detail){
										count +=detail.infoTitle+'<br/>';
									});
								}
								count +='</a>';
								return count;
							 }
						},
						{field : 'publishStatus',title : '发布状态',width : $(this).width() * 0.15,align : 'center',
							formatter:function(value,rec){
								if(value == 1){
									return '<font color="red">预约发布</font>';
								}
								if(value == 3){
									return '<font color="green">已发布</font>';
								}
							 }
						},
						{field : 'applierId',title : '审批人',width : $(this).width() * 0.10,align : 'center'},
						{field : 'createTime',title : '提交时间',width : $(this).width() * 0.15,align : 'center',
							formatter : function(value, rec, index) {
								var str = "";
								if(value != '') {
									str = backendCommon.dateTimeToLocalStringWithSeconds(value);
								}
								return str;
							}
						},
						{field : 'applyTime',title : '审核时间',width : $(this).width() * 0.15,align : 'center',
							formatter : function(value, rec, index) {
								var str = "";
								if(value != '') {
									str = backendCommon.dateTimeToLocalStringWithSeconds(value);
								}
								return str;
							}
						}
					]]
		});
	}
	if(i == 2){
		$('#tt2').datagrid({
			title:'审核未通过列表信息',
			width : backendCommon.getWidth(0.94),
			height : 'auto',
			method:'post',
			loadMsg:"数据装载中,请稍等....",
			url:mainDomain+'/info/infoPublishVerify/findInfoPublishPgByDto.action?publishStatus=2',
			rownumbers:true,
			nowrap: false,
			striped : true,
			fitColumns: true,
			pagination:true,
	        singleSelect:true,
	        pageSize:10,
		    pageNumber:1,          
		    pageList:[10,15,20],
			columns : [[
						{field : 'createBy',title : '提交人',width : $(this).width() * 0.10,align : 'center'},
						{field : 'content',title : '内容',width : $(this).width() * 0.35,align : 'center',
							formatter:function(value,rec){
								var count = '<a onclick="intoEditPublishDetailPage('+rec.id+');" class="publish"  href="javascript:void(0)">';
								if(rec.detailVoList != null && rec.detailVoList.length>0){
									$.each(rec.detailVoList,function(index,detail){
										count +=detail.infoTitle+'<br/>';
									});
								}
								count +='</a>';
								return count;
							 }
						},
						{field : 'applierId',title : '审批人',width : $(this).width() * 0.10,align : 'center'},
						{field : 'remark',title : '审核意见',width : $(this).width() * 0.25,align : 'center'},
						{field : 'applyTime',title : '审核时间',width : $(this).width() * 0.20,align : 'center',
							formatter : function(value, rec, index) {
								var str = "";
								if(value != '') {
									str = backendCommon.dateTimeToLocalStringWithSeconds(value);
								}
								return str;
							}
						}
					]]
		});
	}
};
